package cn.zwh;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import java.awt.Dimension;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;

public class GoBangframe extends JPanel implements GoBangconfig{
    public Graphics g;
    public int[][] isAvail=new int [15][15];
    public static void main(String args[]) {
        GoBangframe gf=new GoBangframe();
        gf.initUI();
    }
    public void initUI() {
        JFrame jf=new JFrame();
        jf.setTitle("周伟恒的五子棋");
        jf.setSize(800,650);
        jf.setLocationRelativeTo(null);
        jf.setDefaultCloseOperation(3);
        jf.setLayout(new BorderLayout());
        Dimension dim1=new Dimension(150,0);
        Dimension dim3=new Dimension(550,0);
        Dimension dim2=new Dimension(140,40);
        this.setPreferredSize(dim3);
        this.setBackground(Color.yellow);
        jf.add(this,BorderLayout.CENTER);
        JPanel jp=new JPanel();
        jp.setPreferredSize(dim1);
        jp.setBackground(Color.blue);
        jf.add(jp,BorderLayout.EAST);
        jp.setLayout(new FlowLayout());
        String[] butname= {"开始新游戏"};
        JButton[] button=new JButton[3];
        for(int i=0;i<butname.length;i++) {
            button[i]=new JButton(butname[i]);
            button[i].setPreferredSize(dim2);
            jp.add(button[i]);
        }
        ButtonListener butListen=new ButtonListener(this);
        for(int i=0;i<butname.length;i++) {
            button[i].addActionListener(butListen);
        }
        jf.setVisible(true);
    }
    public void paint(Graphics g) {
        super.paint(g);
        g.setColor(Color.black);
        for(int i=0;i<row;i++) {
            g.drawLine(x, y+size*i, x+size*(column-1), y+size*i);
        }
        for(int j=0;j<column;j++) {
            g.drawLine(x+size*j, y, x+size*j, y+size*(row-1));
        }
        //重绘出棋子
        for(int i=0;i<row;i++) {
            for(int j=0;j<column;j++) {
                if(isAvail[i][j]==1) {
                    int countx=size*i+20;
                    int county=size*j+20;
                    g.setColor(Color.black);
                    g.fillOval(countx-size/2, county-size/2, size, size);
                }
                else if(isAvail[i][j]==2) {
                    int countx=size*i+20;
                    int county=size*j+20;
                    g.setColor(Color.white);
                    g.fillOval(countx-size/2, county-size/2, size, size);
                }
            }
        }
    }

}

